#include "smartaudio.h"
#include "tsound.h"
#include "../../../core/command.h"

using namespace Commands;
using namespace Commands::Core;

SmartAudio::SmartAudio(char* path, int channel)
: sound(new TSounddias())
, channel(channel)
, playing_channel(channel)
{
    sound->Load(path);
}
//-----------------------------------------------------------------------------
SmartAudio::~SmartAudio()
{
    delete sound;
}
//-----------------------------------------------------------------------------
void SmartAudio::Play(void)
{
    Play(channel);
}
//-----------------------------------------------------------------------------
void SmartAudio::Play(const int channel)
{
    if(channel >= 0)
    {
        sound->Play(channel);
        playing_channel = channel;
    }
}
//-----------------------------------------------------------------------------
void SmartAudio::Stop(void)
{
    sound->Stop();
}
//-----------------------------------------------------------------------------
void SmartAudio::AddCommand(const int queueId, const Command<IAudio>& command)
{
    Command<IAudio>* _command = command.Copy();
    _command->Attach(this);
    AddCommand(queueId, _command);
}
//-----------------------------------------------------------------------------
void SmartAudio::PlayContinous(void)
{
    if(!sound->Status(playing_channel))
    {
        Play(playing_channel);
    }
}
//-----------------------------------------------------------------------------
void SmartAudio::PlayContinous(const int channel)
{
    if(!sound->Status(playing_channel))
    {
        Play(channel);
    }
}
//-----------------------------------------------------------------------------
void SmartAudio::FadeOut(const float seconds)
{
    if(sound->Status(playing_channel))
    {
        sound->FadeOut(int(seconds * 100));
    }
}
//-----------------------------------------------------------------------------
